// http://element-cn.eleme.io/#/zh-CN/component/i18n

import Vue from 'vue'
import VueI18n from 'vue-i18n'
import elementEnLocale from 'element-ui/lib/locale/lang/en' // element-ui lang
import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'// element-ui lang
import ElementLocale from 'element-ui/lib/locale'
import enLocale from './en'
import zhLocale from './zh'

Vue.use(VueI18n)

const messages = {
  en: {
    ...enLocale,
    ...elementEnLocale
  },
  zh: {
    ...zhLocale,
    ...elementZhLocale
  }
}

let userLanguage = localStorage.getItem('CPQ_LANGUAGE') || window.navigator.language || 'en-US'
let locale = 'en'
if (userLanguage.indexOf('zh-') !== -1) {
  locale = 'zh'
}

// FIXME: 需求要求默认为英语，不根据用户语言，不合理看后续要不要改
locale = 'en'

const i18n = new VueI18n({
  locale,
  messages
})

ElementLocale.i18n((key, value) => i18n.t(key, value))

export default i18n
